<extend name="Extends/base"/>
<block name="title">系统设置</block>
<block name="css">
</block>
<block name="body_style">class="bgc-fff"</block>
<block name="body">
    <div class="pt30 plr20">
        <include file="Setting/sysinfo" />
        <div class="c-border-b c-border-d width-100 mtb30"></div>
        <ul class="c-blocks-2 mb40">
            <li id="colorList">
                <div class="clearfix" style="width:90%!important">
                    {//颜色}
                    <div class="form-layout form-inline">
                        <div class="control-group">
                            <a href="javascript:;"
                               class="add-color c-btn c-btn-green mr10">新增颜色</a>
                        </div>
                    </div>
                    <div class="c-nodata pt100 c-t-center">
                        <img src="__PC__/images/nodata.png">
                        <p class="pt30 c-f14 msg"></p>
                    </div>

                    <div class="c-hide cont">
                    </div>
                </div>
            </li>
            <li id="eyeList">
                <div class="clearfix" style="width:90%!important">
                    {//眼砂}
                    <div class="form-layout form-inline">
                        <div class="control-group">
                            <a href="javascript:;"
                               class="add-eye c-btn c-btn-green mr10">新增眼砂</a>
                        </div>
                    </div>
                    <div class="c-nodata pt100 c-t-center">
                        <img src="__PC__/images/nodata.png">
                        <p class="pt30 c-f14 msg"></p>
                    </div>

                    <div class="c-hide cont">
                    </div>
                </div>
            </li>
        </ul>
        <div class="c-border-b c-border-d width-100 mtb30"></div>
        <div class="c-t-center mb30">
            <a href="javascript:;" class="backups-btn c-btn c-btn-green mr10">备份数据库数据</a>
        </div>

    </div>
</block>
<block name="js">

    <script type="text/javascript">
        $(function () {
            getColorList();
            getEyeList();
            $('.upload-img-obj').zoomify();
        });

        /**
         * 提交系统编辑
         * @returns {undefined}
         */
        $(document).on("click", ".sys-submit-btn", function () {
            var data = getFormData($("#sysForm"));
            doEditSysInfo(data, function (res) {
                if (res.Code != 10000) {
                    $.toast(res.Message);
                    return false;
                }
                $.toast("编辑成功", 800, function () {
                    location.reload();
                })
            })
        });

        /**
         * 取消系统编辑
         */
        $(document).on("click", ".cancel-btn", function () {
            location.reload();
        });

        /**
         * 添加砂眼
         */
        $(document).on("click", ".add-eye", function () {
            var type = $(this).attr("data-type");
            var html = '<input type="text" name="setting_type" class="input-text" value="" />';
            var idx = $.alert(html, {
                "title": '添加眼砂',
                "ok": function () {
                    var type = $("input[name=setting_type]").val();
                    doAddEye(type, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        idx.close();
                        $.toast("添加成功", 800, function () {
                            getEyeList();
                        })
                    });
                    return false;
                }
            })
        });

        /**
         * 添加颜色
         */
        $(document).on("click", ".add-color", function () {
            var type = $(this).attr("data-type");
            var html = '<input type="text" name="setting_type" class="input-text" value="" />';
            var idx = $.alert(html, {
                "title": '添加颜色',
                "ok": function () {
                    var type = $("input[name=setting_type]").val();
                    doAddColor(type, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        idx.close();
                        $.toast("添加成功", 800, function () {
                            getColorList();
                        })
                    });
                    return false;
                }
            })
        });

        /**
         * 编辑砂眼
         */
        $(document).on("click", ".edit-eye", function () {
            var id = $(this).attr("data-id");
            var type = $(this).attr("data-type");
            var html = '<input type="text" name="setting_type" class="input-text" value="' + type + '" />';
            var idx = $.alert(html, {
                "title": '编辑眼砂',
                "ok": function () {
                    var type = $("input[name=setting_type]").val();
                    doEditEye(id, type, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        idx.close();
                        $.toast("编辑成功", 800, function () {
                            getEyeList();
                        })
                    });
                    return false;
                }
            })
        });

        /**
         * 编辑颜色
         */
        $(document).on("click", ".edit-color", function () {
            var id = $(this).attr("data-id");
            var type = $(this).attr("data-type");
            var html = '<input type="text" name="setting_type" class="input-text" value="' + type + '" />';
            var idx = $.alert(html, {
                "title": '编辑眼砂',
                "ok": function () {
                    var type = $("input[name=setting_type]").val();
                    doEditColor(id, type, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        idx.close();
                        $.toast("编辑成功", 800, function () {
                            getColorList();
                        })
                    });
                    return false;
                }
            })
        });

        /**
         * 删除眼睛
         */
        $(document).on("click", ".del-eye", function () {
            var id = $(this).attr("data-id");
            var idx = $.alert("是否确认删除", {
                "title": '删除',
                "ok": function () {
                    doDelEye(id, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        idx.close();
                        $.toast("删除成功", 800, function () {
                            getEyeList();
                        })
                    });
                    return false;
                }
            })
        });

        /**
         * 删除颜色
         */
        $(document).on("click", ".del-color", function () {
            var id = $(this).attr("data-id");
            var idx = $.alert("是否确认删除", {
                "title": '删除',
                "ok": function () {
                    doDelColor(id, function (res) {
                        if (res.Code != 10000) {
                            $.toast(res.Message);
                            return false;
                        }
                        idx.close();
                        $.toast("删除成功", 800, function () {
                            getColorList();
                        })
                    });
                    return false;
                }
            })
        });

        $('.backups-btn').on("click", function () {
            doBackups(function (res) {
                if (res.Code != 10000) {
                    $.toast(res.Message);
                    return false;
                }

                var url = res.Result;
                $.alert("数据备份成功,备份文件：" + url);
            });
        })

        /**
         * 获取颜色列表
         * @returns {undefined}
         */
        function getColorList() {
            var $parent = $('#colorList');
            doGetColorList(function (res) {
                if (res.Code != 10000) {
                    showErr($parent, res.Message);
                    return false
                }
                var html = res.Result.html;
                hideErr($parent);
                $parent.find(".cont").html(html).show();
            });
        }

        /**
         * 获取眼睛列表
         * @returns {undefined}
         */
        function getEyeList() {
            var $parent = $('#eyeList');
            doGetEyeList(function (res) {
                if (res.Code != 10000) {
                    showErr($parent, res.Message);
                    return false
                }
                var html = res.Result.html;
                hideErr($parent);
                $parent.find(".cont").html(html).show();
            });
        }

        /**
         * 显示页面错误页面
         * @param {type} $parent
         * @param {type} msg
         * @returns {undefined}
         */
        function showErr($parent, msg) {
            $parent.find('.c-nodata').show().find('.msg').html(msg);
        }

        /**
         * 隐藏错误页面
         * @param {type} $parent
         * @returns {undefined}
         */
        function hideErr($parent) {
            $parent.find('.c-nodata').hide().find('.msg').text('');
        }

        /**
         * 点击上传图片
         */
        $(document).on("click", ".upload-img", function () {
            var $t = $(this);
            var $input = $t.parents(".fileupload-wrap").find("input[type=hidden]");
            $.imgUpload(function (res) {
                if (res.Code != 10000) {
                    $.toast(res.Message);
                    return false;
                }

                var url = res.Result.url;
                $input.val(url);
                var html = '\
                    <div class="upload-img-show c-position-r" style="height:130px; width:90px;">\
                        <img src="' + url + '" class="upload-img-obj" style="width:90px;" />\
                        <a href="javascript:;" class="c-position-a fileupload-img-del">\
                            <i class="iconfont">\
                                <img class="close-img" src="/pigeonSys/Public/Console/images/closebtn.png" width="20">\
                            </i>\
                        </a>\
                    </div>'

                $t.replaceWith(html);
                $('.upload-img-obj').zoomify();
            });
        });

        /**
         * 点击删除图片
         */
        $(document).on("click", ".close-img", function () {
            var $wrap = $(this).parents(".upload-img-show");
            var $input = $(this).parents(".fileupload-wrap").find("input[type=hidden]");
            $input.val("");
            var html = '\
                <span class="upload-img btn-file btn-file-3 fileinput-button">\
                    <i class="c-f22" >+</i>\
                </span>';
            $wrap.replaceWith(html);
        });
    </script>
</block>

<block name="jsFile">

    <!--上传图片样式-->
    <link rel="stylesheet" href="__PC__/widget/fileUpload/9.11.2/css/jquery.fileupload.min.css" type="text/css" />

    <!--图片上传-->
    <script type="text/javascript" src="__CST__/js/imgUpload.js?v={:C('JS_CSS_VERSION')}"></script>

    <!--图像展示-->
    <link rel="stylesheet" href="__PC__/widget/zoomify/zoomify.css?v={:C('JS_CSS_VERSION')}" type="text/css" />
    <script type="text/javascript" src="__PC__/widget/zoomify/zoomify.js?v={:C('JS_CSS_VERSION')}"></script>

    <script type="text/javascript" src="__CST__/js/api.js?v={:C('JS_CSS_VERSION')}"></script>
    <script type="text/javascript" src="__CST__/js/setting.api.js?v={:C('JS_CSS_VERSION')}"></script>
</block>

